#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        #if(resourceList != null)
            <div class="easyui-panel" title="工具栏" style="width:100%;padding:10px;" data-options="iconCls:'icon-application_form'">
                #for(resource : resourceList)
                    <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
                #end
            </div>
            <br>
        #end

        <div class="easyui-panel" title="配置信息" style="width:100%;padding:10px;"
             data-options="iconCls:'icon-application_form'">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">#(_res.get('facet.form.prop.name'))</div>
                        <div class="fht-cell"></div>
                    </th>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">属性说明</div>
                        <div class="fht-cell"></div>
                    </th>
                    <th tabindex="0" data-field="facet_name" style="">
                        <div class="th-inner sortable both">#(_res.get('facet.form.prop.value'))</div>
                        <div class="fht-cell"></div>
                    </th>
                </tr>
                </thead>
                <tbody>
                #--=========================== 循环遍历属性开始 ==============================--#
                #for(sysConfig : sysList)
                    <tr>
                        <td>
                            <a href="javascript:void(0);"
                               title="#(_res.get(sysConfig.configCname))"
                               class="easyui-tooltip">#(sysConfig.configEname)</a>
                        </td>
                        <td>
                            #(_res.get(sysConfig.configCname))
                        </td>
                        <td>

                            #if(sysConfig.dataType == 'boolean')
                                <select name="#(sysConfig.configId)" id="#(sysConfig.configId)" onchange="editText(this)" style="width: 400px;" dataType="#(sysConfig.dataType)" regex="#(sysConfig.regex)" errorMsg="#(sysConfig.errorMsg)" configName="#(sysConfig.configEname)">
                                    <option value="true" #(sysConfig.configValue == 'true' ? 'selected':'')>true</option>
                                    <option value="false" #(sysConfig.configValue == 'false'  ? 'selected':'')>false
                                    </option>
                                </select>

                            #elseif(sysConfig.dataType == 'string')
                            <input id="#(sysConfig.configId)" type="text" value='#(sysConfig.configValue)' onchange="editText(this)" style="width: 400px;" dataType="#(sysConfig.dataType)" regex="#(sysConfig.regex)" errorMsg="#(sysConfig.errorMsg)" configName="#(sysConfig.configEname)"/>

                            #elseif(sysConfig.dataType == 'number')
                            <input id="#(sysConfig.configId)" type="text" value="#(sysConfig.configValue)" onchange="editText(this)" style="width: 400px;" dataType="#(sysConfig.dataType)" regex="#(sysConfig.regex)" errorMsg="#(sysConfig.errorMsg)" configName="#(sysConfig.configEname)"/>

                            #elseif(sysConfig.dataType == 'json')
                            <input id="#(sysConfig.configId)" type="text" value='#(sysConfig.configValue)' onchange="editText(this)" style="width: 400px;" dataType="#(sysConfig.dataType)" regex="#(sysConfig.regex)" errorMsg="#(sysConfig.errorMsg)" configName="#(sysConfig.configEname)"/>

                            #end

                        </td>
                    </tr>
                #end
                #--=========================== 循环遍历属性结束 ==============================--#
                </tbody>
            </table>
        </div>
    </div>


</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">

    function editText(t) {
        var element = $(t);
        var dataType = element.attr("dataType");
        var regex = element.attr("regex");
        var errorMsg = element.attr("errorMsg");
        var flag = true;

        if (regex !== '' && regex !== 'null') {//如果设置了正则表达式，则对内容进行验证
            regex = eval("(" + regex + ")");
            flag = regex.test(element.val());
        }

        if(dataType === 'json'){//校验JSON格式
            try{
                JSON.parse(element.val());
            }catch (e) {
                flag = false;
            }
        }

        if (flag) {
            var url = contextRootPath + '/uasConfig/update/sys';
            var params = {"uasConfig.config_value": element.val(), "uasConfig.config_id": element.attr("id"),"uasConfig.config_ename":element.attr("configName")};
            $.post(url, params, function (result) {
                if (!result) {
                    $.messager.alert('提示', "数据请求出现异常，请稍后重试");
                    return;
                }

                $.messager.alert('提示', result);
                $('.error_sty').removeClass('error_sty').tooltip('destroy');
            });
        } else {
            $.messager.alert('提示框', errorMsg);
            element.addClass('error_sty');
            element.tooltip({
                position: 'top',
                content: errorMsg
            });
        }
    }

    $(function () {
    #for(resource : resourceList)
        
        #if(resource.url == 'uasConfig_sysBack' || resource.url == 'uasConfig_redisBack')
            $("#uasConfig_sysBack").on('click', function () {

                var url = contextRootPath + '/uasConfig/sysBack';
                var params = {};
                params.configType = #(configType);
                $.post(url, params, function (result) {
                    if (!result) {
                        $.messager.alert("提示", "数据请求出现异常，请稍后重试");
                        return;
                    }

                    $.messager.alert('提示', result, 'info', function () {
                        location.reload();
                    });
                });
            });
        
        #elseif(resource.url == 'uasConfig_setDefValByK')
            $("#uasConfig_setDefValByK").on('click', function () {

                var keyArr = $(".table a");
                var valueArr = $("input,select");
                var keyParam = '', valueParam = '';
                var sep = ",";

                keyArr.each(function (i, v) {
                    keyParam += $(v).text() + sep;
                });

                valueArr.each(function (i, v) {
                    valueParam += $(v).val() + sep;
                });

                var url = contextRootPath + '/uasConfig/setDefValByK';
                var params = {keyParam: keyParam, valueParam: valueParam};
                $.post(url, params, function (result) {
                    if (!result) {
                        $.messager.alert('提示', "数据请求出现异常，请稍后重试");
                        return;
                    }

                    $.messager.alert('提示', result, 'info', function () {
                        location.reload();
                    });
                });
            });
        #end
     #end
    });

</script>

#end



